package com.hillinsight.controller;

import com.hillinsight.service.HiveService;
import com.hillinsight.service.MySQLService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by fangzheng on 2018/9/3.
 */
@Controller
public class IndexController {

    @Autowired
    private MySQLService mySQLService;

    @Autowired
    private HiveService hiveService;

    private Map<String,List> getAllDatabases(){
        Map<String,List> alldatabases = new HashMap<>();
        List mysqlDatabases = mySQLService.getAllDatabases("SELECT TABLE_SCHEMA FROM information_schema.TABLES GROUP BY TABLE_SCHEMA;");
        alldatabases.put("MySQL",mysqlDatabases);

        List hiveDatabases = hiveService.getAllDatabases();
        alldatabases.put("Hive",hiveDatabases);
        return alldatabases;
    }

    @RequestMapping("/")
    public String index(Model model){
        model.addAttribute("menus",getAllDatabases());
        return "index";
    }

    @RequestMapping("/welcome")
    public String welcome(){
        return "welcome";
    }


    @RequestMapping("/unicode")
    public String unicode(){
        return "unicode";
    }
}
